//
//  WHAuthorMoreCell.m
//  GroupFourFM
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WHAuthorMoreCell.h"

@interface WHAuthorMoreCell ()

@property (nonatomic, strong) UIButton *button;

@end

@implementation WHAuthorMoreCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubs];
    }
    
    return self;
}


-(void)createSubs{
    
    self.authorPic = [[UIImageView alloc] init];
    [self.contentView addSubview:self.authorPic];
    
    [self.authorPic mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.mas_equalTo(@0);
        make.bottom.mas_equalTo(@-10);
        make.width.equalTo(self.contentView.mas_height).offset(-10);
        
    }];
    
    self.authorName = [UILabel new];
    [self.contentView addSubview:self.authorName];
    
    [self.authorName mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.authorPic.mas_right).offset(10);
        make.top.mas_equalTo(@15);
        make.right.mas_equalTo(@-20);
        make.height.mas_equalTo(@20);
        
    }];
    
    self.authorDescribe = [UILabel new];
    [self.contentView addSubview:self.authorDescribe];
    self.authorDescribe.font = [UIFont systemFontOfSize:14.f];
    self.authorDescribe.alpha = 0.5;
    [self.authorDescribe mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.equalTo(self.authorName);
        make.top.equalTo(self.authorName.mas_bottom).offset(10);
        make.height.equalTo(self.authorName);
        
        
    }];
    
    UIImageView *iconImageV = [[UIImageView alloc] init];
    iconImageV.backgroundColor = CLEAR;
    iconImageV.image = [UIImage imageNamed:@"album_tracks"];
    [self.contentView addSubview:iconImageV];
    
    [iconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.authorPic.mas_right).offset(10);
        make.top.equalTo(self.authorDescribe.mas_bottom).offset(15);
        make.width.height.mas_equalTo(@15);
        
        
    }];
    
    
    //播放人数
    self.tracksLabel = [[UILabel alloc] init];
    self.tracksLabel.backgroundColor = CLEAR;
    self.tracksLabel.font = [UIFont systemFontOfSize:13 weight:0];
    [self.contentView addSubview:self.tracksLabel];
    self.tracksLabel.textAlignment = NSTextAlignmentLeft;
    self.tracksLabel.textColor = [UIColor lightGrayColor];
    
    [self.tracksLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.authorPic.mas_right).offset(30);
        make.top.equalTo(self.authorDescribe.mas_bottom).offset(15);
        make.height.mas_equalTo(@15);
        make.width.mas_equalTo(@30);
        
    }];
    
    UIImageView *iconImage = [[UIImageView alloc] init];
    iconImage.backgroundColor = CLEAR;
    iconImage.image = [UIImage imageNamed:@"find_hotUser_fans"];
    [self.contentView addSubview:iconImage];
    
    [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.tracksLabel.mas_right).offset(10);
        make.top.equalTo(self.authorDescribe.mas_bottom).offset(15);
        make.height.width.mas_equalTo(@15);
        
    }];
    
    //关注人数
    self.followersLabel = [[UILabel alloc] init];
    self.followersLabel.backgroundColor = CLEAR;
    self.followersLabel.font = [UIFont systemFontOfSize:13 weight:0];
    [self.contentView addSubview:self.followersLabel];
    self.followersLabel.textAlignment = NSTextAlignmentLeft;
    self.followersLabel.textColor = [UIColor lightGrayColor];
    
    [self.followersLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.tracksLabel.mas_right).offset(30);
        make.top.equalTo(self.authorDescribe.mas_bottom).offset(15);
        make.height.mas_equalTo(@15);
        make.right.mas_equalTo(@-20);
        
        
        
    }];
    
    UIImageView *coverImage = [[UIImageView alloc] init];
    coverImage.backgroundColor = [UIColor lightGrayColor];
    coverImage.alpha = 0.3f;
    //coverImage.image = [UIImage imageNamed:@"find_pop_footer"];
    [self.contentView addSubview:coverImage];
    
    [coverImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.authorPic.mas_bottom);
        make.left.right.mas_equalTo(@0);
        make.bottom.equalTo(@0);
    }];

    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.button setBackgroundImage:[UIImage imageNamed:@"find_radio_focuse"] forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(buttonActionF:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button];
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(@-10);
        make.bottom.equalTo(@-20);
        make.width.equalTo(@(117/2));
        make.height.equalTo(@(47/2));
    }];

    
}

-(void)buttonActionF:(UIButton *)btn {
    

    [self.delegate collectAuthor:_authorM];

}

-(void)setAuthorM:(WSAuthorModel *)authorM{
    
    _authorM = authorM;
    
    [self.authorPic sd_setImageWithURL:[NSURL URLWithString:_authorM.largeLogo] placeholderImage:nil];
    if (_authorM.objectId != nil) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"find_radio_focuse_sel"] forState:UIControlStateNormal];
    } else {
        [self.button setBackgroundImage:[UIImage imageNamed:@"find_radio_focuse"] forState:UIControlStateNormal];
    }
    self.authorName.text = _authorM.nickname;
    self.authorDescribe.text = _authorM.personDescribe;
    self.tracksLabel.text = [NSString stringWithFormat:@"%ld",_authorM.tracksCounts];
    self.followersLabel.text = [NSString stringWithFormat:@"%.2f万",(CGFloat)_authorM.followersCounts/10000];
    
}

@end
